package com.y.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.y.entity.Food;
import com.y.entity.vo.DataTable;
import com.y.mapper.FoodMapper;
import com.y.service.FoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Yjh
 * @since 2021-09-24
 */
@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food> implements FoodService {

    @Resource
    FoodMapper foodMapper;

    @Override
    public DataTable<Food> getFoodList(Integer page, Integer limit, String name, String kind) {
        // 查询条件 生效条件
        Page<Food> pageInfo = PageHelper.startPage(page,limit);
        List<Food> foodList = foodMapper.getFoodList(name, kind);

        return new DataTable<>((int)pageInfo.getTotal(),foodList);
    }

    /**
     * 获取所有食品集合
     * @return
     */
    @Override
    public List<Food> getAllFoodList() {
        return foodMapper.getFoodList(null, null);
    }

}
